//
//  ListModel.swift
//  Pods
//
//  Created by eme on 2017/3/31.
//
//

import Foundation
import SwiftyJSON
import NetWorkCore
import ModelProtocol

class ListModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kListBrnameKey: String = "brname"
    internal let kListPdnameKey: String = "pdname"
    internal let kListPdstateKey: String = "pdstate"
    internal let kListPdidKey: String = "pdid"
    internal let kListCrdateKey: String = "crdate"
    internal let kListImg1Key: String = "img1"
    internal let kListMoqKey: String = "moq"
    internal let kListPddesKey: String = "pddes"
    internal let kListPdunitKey: String = "pdunit"
    internal let kListUseridKey: String = "userid"
    internal let kListBridKey: String = "brid"
    internal let kListProfitKey: String = "profit"
    internal let kListFidKey: String = "fid"
    internal let kListShpriceKey: String = "shprice"
    internal let kListSalecountKey: String = "salecount"
    internal let kListStockKey: String = "stock"
    internal let kListIstimebyKey: String = "istimeby"
    
    
    
    
    // MARK: 属性
    var brname: String
    var pdname: String
    var pdstate: String
    var pdid: Int
    var crdate: String
    var img1: String
    var moq: Int
    var pddes: String
    var pdunit: String
    var userid: Int
    var brid: String
    var profit: Int
    var fid: Int
    var shprice: Double
    var salecount: Int
    var stock:Int
    var isclicked = 0
    var istimeby:String
    var isSoldout = false
    var isfailure = false
    var bdprice:Double
    
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        brname = json[kListBrnameKey].stringValue
        pdname = json[kListPdnameKey].stringValue
        pdstate = json[kListPdstateKey].stringValue
        pdid = json[kListPdidKey].intValue
        crdate = json[kListCrdateKey].stringValue
        img1 = json[kListImg1Key].stringValue
        moq = json[kListMoqKey].intValue
        pddes = json[kListPddesKey].stringValue
        pdunit = json[kListPdunitKey].stringValue
        userid = json[kListUseridKey].intValue
        brid = json[kListBridKey].stringValue
        profit = json[kListProfitKey].intValue
        fid = json[kListFidKey].intValue
        shprice = json[kListShpriceKey].doubleValue
        salecount = json[kListSalecountKey].intValue
        stock = json[kListStockKey].intValue
        istimeby = json[kListIstimebyKey].stringValue
        bdprice = json["bdprice"].doubleValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        
        dictionary.updateValue(brname as AnyObject, forKey: kListBrnameKey)
    
        dictionary.updateValue(pdname as AnyObject, forKey: kListPdnameKey)
    
        dictionary.updateValue(pdstate as AnyObject, forKey: kListPdstateKey)
    
        dictionary.updateValue(pdid as AnyObject, forKey: kListPdidKey)
    
        dictionary.updateValue(crdate as AnyObject, forKey: kListCrdateKey)
    
        dictionary.updateValue(img1 as AnyObject, forKey: kListImg1Key)
    
        dictionary.updateValue(moq as AnyObject, forKey: kListMoqKey)
    
        dictionary.updateValue(pddes as AnyObject, forKey: kListPddesKey)
    
        dictionary.updateValue(pdunit as AnyObject, forKey: kListPdunitKey)
    
        dictionary.updateValue(userid as AnyObject, forKey: kListUseridKey)
    
        dictionary.updateValue(brid as AnyObject, forKey: kListBridKey)
    
        dictionary.updateValue(profit as AnyObject, forKey: kListProfitKey)
    
        dictionary.updateValue(fid as AnyObject, forKey: kListFidKey)
    
        dictionary.updateValue(shprice as AnyObject, forKey: kListShpriceKey)
    
        dictionary.updateValue(salecount as AnyObject, forKey: kListSalecountKey)
    
        dictionary.updateValue(stock as AnyObject, forKey: kListStockKey)
   
        dictionary.updateValue(istimeby as AnyObject, forKey: kListIstimebyKey)
        
        dictionary.updateValue(bdprice as AnyObject, forKey: "bdprice")
        
        
        return dictionary
    }
    
    
}
